import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 组织机构类型枚举 */
export enum OrganizationTypeEnum {
  /** 虚拟组织 */
  Virtual = 1,
  /** 法人组织 */
  Corporation = 2,
  /** 部门组织 */
  Department = 3,
}

/** 组织机构类型实体 */
export class OrganizationTypeEntity {
  /** 组织机构类型 */
  OrganizationType: OrganizationTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(organizationType: OrganizationTypeEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.OrganizationType = organizationType;
    this.Color = color;
    switch (organizationType) {
      case OrganizationTypeEnum.Virtual:
        // this.Display = '虚拟';
        this.Display = t('enum.organizationType.virtual');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
      case OrganizationTypeEnum.Corporation:
        // this.Display = '法人';
        this.Display = t('enum.organizationType.corporation');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case OrganizationTypeEnum.Department:
        // this.Display = '部门';
        this.Display = t('enum.organizationType.department');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
    }
  }
}

//#region 获取组织机构类型枚举架构
/**
 * 获取组织机构类型枚举架构
 */
export function getOrganizationTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: OrganizationTypeEntity[] = [
    new OrganizationTypeEntity(OrganizationTypeEnum.Virtual),
    new OrganizationTypeEntity(OrganizationTypeEnum.Corporation),
    new OrganizationTypeEntity(OrganizationTypeEnum.Department),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.OrganizationType as number,
      label: item.Display,
      value: item.OrganizationType as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
